package org.bluedream.core.module.dao.bill.stkIn.dtl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.bluedream.core.module.entity.bill.stkIn.dtl.StkInDtl;

/**
 * @ClassName StkInDtlDao
 * @Description TODO
 * @Author foxsand
 * @Data 14:47
 * @Version
 */
public interface StkInDtlDao extends BaseMapper<StkInDtl> {
    @Override
    @Select("select StkInDtl.bill_type as billType , StkInDtl.bill_num as billNum , StkInDtl.code as code, b.barcode as barcode, b.name as name, StkInDtl.qty as qty ," +
            " StkInDtl.id as id , StkInDtl.create_by as createBy , StkInDtl.create_date as createDate , StkInDtl.update_by as updateBy , StkInDtl.update_date as updateDate , StkInDtl.status as status , StkInDtl.remarks as remarks , " +
            "   case " +
            "       when mod(StkInDtl.qty , b.qpc) = 0 then to_char(StkInDtl.qty / b.qpc)  " +
            "       when mod(StkInDtl.qty , b.qpc) != 0  and StkInDtl.qty/b.qpc = 0 then to_char(floor(StkInDtl.qty/b.qpc))||'+'||to_char(StkInDtl.qty) " +
            "       when mod(StkInDtl.qty , b.qpc) != 0  and StkInDtl.qty/b.qpc != 0 then to_char(floor(StkInDtl.qty/b.qpc))||'+'||to_char(StkInDtl.qty - b.qpc) end as qtyStr , " +
            "b.qpc as qpc , b.qpc_str as qpcStr , b.unit as unit , b.spec as spec , StkInDtl.oprice as oprice , StkInDtl.total as total " +
            "from StkInDtl StkInDtl , goods b " +
            " ${ew.customSqlSegment} and StkInDtl.code = b.code ")
    IPage<StkInDtl> selectPage(IPage<StkInDtl> page, @Param("ew") Wrapper<StkInDtl> wrapper);
}
